<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>院感不良事件上报表</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <style>
        td{
            padding-left: 10px;
            padding-bottom: 5px;
            padding-right: 20px;
            padding-top: 10px;
        }
    </style>
</head>
<body>
<form class="layui-form" lay-filter="FormLoad">
    <table border="1px" width="100%" cellpadding="0">
        <tr >
            <td colspan="8" style="text-align: center; height: 50px"> <span style=" font-size: 20px">医院感染不良事件报告表</span> </td>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1" width="16.6%">
                    报告时间：
                </td>
                <td colspan="2" width="33.2%">
                    <input type="text" name="report_date" id="report_date" placeholder="" class="layui-input">
                </td>
                <td colspan="1" width="16.2%">
                    报告科室：
                </td>
                <td colspan="2" width="33.2%">
                    <input type="text" name="reporter_department" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <td rowspan="2" colspan="1">
                发生经过(发生时间，地点，事件内容，产生后果，采取的补偿措施与结果)：
            </td>
            <div class="layui-form-item">
                <td colspan="3" rowspan="2">
                    <textarea name="bad_event_describe" style="height: 80px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
                <td colspan="1">
                    签名
                </td>
                <td colspan="1" >
                    <input type="text" name="reporter_sign" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1">
                    日期
                </td>
                <td colspan="1" >
                    <input type="text" name="reporter_sign_time" id="reporter_sign_time" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>

        <tr>
            <td rowspan="2" colspan="1">
                科内讨论分析（原因，教训，性质，处理意见）
            </td>
            <div class="layui-form-item">
                <td colspan="3" rowspan="2">
                    <textarea name="department_analyse" style="height: 80px" required lay-verify="" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
                <td colspan="1">
                    签名
                </td>
                <td colspan="1" >
                    <input type="text" name="department_analyse_sign" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1">
                    日期
                </td>
                <td colspan="1" >
                    <input type="text" name="department_analyse_sign_time" id="department_analyse_sign_time" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <td rowspan="2" colspan="1">
                院感科质量安全分析及处理意见：
            </td>
            <div class="layui-form-item">
                <td colspan="3" rowspan="2">
                    <textarea name="infection_control_dept_analyse" style="height: 80px" required lay-verify="" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
                <td colspan="1" width="8.3%">
                    签名
                </td>
                <td colspan="1" width="24.9%">
                    <input type="text" name="infection_control_dept_analyse_sign" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1">
                    日期
                </td>
                <td colspan="1" >
                    <input type="text" name="infection_control_dept_analyse_sign_time" id="infection_control_dept_analyse_sign_time" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
    </table>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center; margin-top: 50px">
            <button class="layui-btn" lay-submit lay-filter="YiLiaoqx">立即提交</button>
            <button class="layui-btn" lay-submit lay-filter="save">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script>

    function getQueryVariable(variable)
    {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        for (let i=0;i<vars.length;i++) {
            let pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }
    layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
        let $ = layui.jquery;
        let form = layui.form;
        let laydate = layui.laydate;
        var layer = layui.layer;
        var router = layui.router();
        laydate.render({
            elem: '#report_date' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#reporter_sign_time' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#department_analyse_sign_time' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#infection_control_dept_analyse_sign_time' //指定元素
            , type: 'date'
        });


        form.render();
        // 获取地址的中的值
        let user_code=decodeURIComponent(getQueryVariable("user_code"));
        let user_name=decodeURIComponent(getQueryVariable("user_name"));
        let dept_code=decodeURIComponent(getQueryVariable("dept_code"));
        let dept_name=decodeURIComponent(getQueryVariable("dept_name"));
        // layui data 保存数据
        if( user_code=="undefined"){
            console.log(layui.data('user').userinfo.user_name)
        } else{
            console.log(user_code);
            console.log("地址有值")
            layui.data('user', {
                key: 'userinfo',
                value:
                    {
                        user_name: user_name,
                        user_code: user_code,
                        dept_code:dept_code,
                        dept_name:dept_name
                    }
            });
            console.log(layui.data('user').userinfo.user_name)
        }
        var month=parseInt(1)+parseInt(new Date().getMonth())
        //渲染 上报人和上报人单位
        form.val("FormLoad",{
            "reporter": layui.data('user').userinfo.user_name.replace(/\"/g, "") ,
            "reporter_department":layui.data('user').userinfo.dept_name.replace(/\"/g, ""),
            "report_date": new Date().getFullYear()+"-"+month+"-"+ new Date().getDate()
        })



        // submit 提交事件监听
        form.on('submit(YiLiaoqx)', function(data) {

            layer.confirm('确定提交吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: '/event/event_insert',
                    type: "POST",
                    data:{
                        "reporter_code":layui.data('user').userinfo.user_code,
                        "reporter_name":layui.data('user').userinfo.user_name,
                        "dept_code":layui.data('user').userinfo.dept_code,
                        "dept_name":layui.data('user').userinfo.dept_name,
                        "event_code":8,
                        "report_date":data.field.report_date,
                        "reporter_department":data.field.reporter_department,
                        "bad_event_describe":data.field.bad_event_describe,
                        "reporter_sign":data.field.reporter_sign,
                        "reporter_sign_time":data.field.reporter_sign_time,
                        "department_analyse":data.field.department_analyse,
                        "department_analyse_sign":data.field.department_analyse_sign,
                        "department_analyse_sign_time":data.field.department_analyse_sign_time,
                        "infection_control_dept_analyse":data.field.infection_control_dept_analyse,
                        "infection_dept_analyse_sign":data.field.infection_control_dept_analyse_sign,
                        "infection_dept_analyse_sign_time":data.field.infection_control_dept_analyse_sign_time,
                        "status":2 //递交
                    },
                    success:function () {
                        layer.msg("保存成功");
                        form.val("FormLoad",{
                            "report_date":null,
                            "reporter_department":null,
                            "bad_event_describe":null,
                            "reporter_sign":null,
                            "reporter_sign_time":null,
                            "department_analyse":null,
                            "department_analyse_sign":null,
                            "department_analyse_sign_time":null,
                            "infection_control_dept_analyse":null,
                            "infection_dept_analyse_sign":null,
                            "infection_dept_analyse_sign_time":null,
                        })
                        form.render();
                    },
                })

            }, function () {
            });
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //save 保存事件监听
        form.on('submit(save)', function(data) {
            $.ajax({
                url: '/event/event_insert',
                type: "POST",
                data:{
                    "reporter_code":layui.data('user').userinfo.user_code,
                    "reporter_name":layui.data('user').userinfo.user_name,
                    "dept_code":layui.data('user').userinfo.dept_code,
                    "dept_name":layui.data('user').userinfo.dept_name,
                    "event_code":8,
                    "report_date":data.field.report_date,
                    "reporter_department":data.field.reporter_department,
                    "bad_event_describe":data.field.bad_event_describe,
                    "reporter_sign":data.field.reporter_sign,
                    "reporter_sign_time":data.field.reporter_sign_time,
                    "department_analyse":data.field.department_analyse,
                    "department_analyse_sign":data.field.department_analyse_sign,
                    "department_analyse_sign_time":data.field.department_analyse_sign_time,
                    "infection_control_dept_analyse":data.field.infection_control_dept_analyse,
                    "infection_dept_analyse_sign":data.field.infection_control_dept_analyse_sign,
                    "infection_dept_analyse_sign_time":data.field.infection_control_dept_analyse_sign_time,
                    "status": 1//1表示保存，可修改
                },
                success:function () {
                    layer.msg("保存成功");
                    form.val("FormLoad",{
                        "report_date":null,
                        "reporter_department":null,
                        "bad_event_describe":null,
                        "reporter_sign":null,
                        "reporter_sign_time":null,
                        "department_analyse":null,
                        "department_analyse_sign":null,
                        "department_analyse_sign_time":null,
                        "infection_control_dept_analyse":null,
                        "infection_dept_analyse_sign":null,
                        "infection_dept_analyse_sign_time":null,
                    })
                    form.render();
                },
            });
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>

</html>